package cn.tedu.boot04.controller;

import cn.tedu.boot04.entity.Product;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class AxiosController {
    @RequestMapping("/helloAxios")
    public String helloAxios(String name, int age){
        return "测试成功,name="+name+",age="+age;
    }

    @RequestMapping("/postAxios")
    //如果发出的请求方式为post并且传递过来的是自定义JS对象接收参数是需要添加
    //@RequestBody注解,否则接收到的参数为null
    public String postAxios(@RequestBody Product product){
        return "post测试成功"+ product.toString();
    }

    @RequestMapping("/bmi")
    public String bmi(double h, double w){
        double res = w /(h * h);
        if (res<18) {
            return "偏瘦";
        }
        if (res<24) {
            return "正常";
        }
        if (res<28) {
            return "偏胖";
        }
        if (res<32) {
            return "肥胖";
        }
        return "过度肥胖";
    }
}
